package com.lesso.yzh.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.yzh.sunflower.domain.repository.DeviceRepository;
import com.lesso.yzh.sunflower.infra.assembler.DeviceAssembler;
import com.lesso.yzh.sunflower.model.Device;
import com.lesso.yzh.sunflower.pojo.dto.DeviceDTO;
import com.lesso.yzh.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.yzh.sunflower.pojo.dto.DeviceUpdateDTO;
import com.lesso.yzh.sunflower.pojo.vo.DeviceVO;
import org.springframework.stereotype.Service;

@Service
public class DeviceDomainService {
    private final DeviceRepository deviceRepository;

    public DeviceDomainService(DeviceRepository deviceRepository) {
        this.deviceRepository = deviceRepository;
    }

    public Integer save(DeviceDTO dto) {
        Device device = DeviceAssembler.INSTANCE.dtoToEntity(dto);
        return deviceRepository.save(device);
    }

    public Integer update(DeviceUpdateDTO dto) {
        Device device = DeviceAssembler.INSTANCE.dtoToUpdateEntity(dto);
        return deviceRepository.update(device);
    }

    public void deleteById(Long id) {
        deviceRepository.removeById(id);
    }

    public Page<DeviceVO> page(DeviceQueryDTO dto) {
        return deviceRepository.getPageList(dto);
    }

    public Page<DeviceVO> customPage(DeviceQueryDTO dto) {
        return deviceRepository.getCustomPageList(dto);
    }
}
